package copyfile02;

import java.io.*;

/**
 * 利用BufferedReader和BufferedWriter拷贝文本文件
 *  拷贝9.txt
 */
public class CopyFileDemo01 {
	public static void main(String[] args) throws IOException {
		//method01();
		//1.利用BufferedReader和BufferedWriter关联源文件和目的文件
		BufferedReader br = new BufferedReader(new FileReader("day24/9.txt"));
		BufferedWriter bw = new BufferedWriter(new FileWriter("day24/9_copy_2.txt"));

		//2.利用readLine()方法读文件内容
		String line;
		while ((line = br.readLine()) != null) {
           bw.write(line);
           //bw.write("\r\n");//写入\r\n只针对windows换行有效
			bw.newLine();
		}
		//3.关流释放资源
		br.close();
		bw.close();
	}

	private static void method01() throws IOException {
		//1.利用BufferedReader和BufferedWriter关联源文件和目的文件
		BufferedReader br = new BufferedReader(new FileReader("day24/9.txt"));
		BufferedWriter bw = new BufferedWriter(new FileWriter("day24/9_copy.txt"));

		//2.进行读写操作
		int ch;
		while ((ch =br.read())!=-1) {//read()无论文本文件是什么内容都会读取(包括换行符)
             bw.write(ch);
		}
		//3.关流释放资源
		br.close();
		bw.close();
	}
}
